
public class IsArrayFibonacci {
	public static void main(String[] args) {

	    int iArr1[] = {2, 1, 9, 6, 4, 8, 55, 77, 41, 0, 4};
	    int iArr2[] = {0, 1, 1, 2, 3, 5, 8, 13, 21,55};
	    int iArr3[] = {0, 1, 1, 2, 7, 5, 8, 13, 21, 34};
	    int iArr4[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 34};
	    
	    System.out.println("iArr1 Fibonacci: "+ isFibonacci(iArr1));
	    System.out.println("iArr2 Fibonacci: "+ isFibonacci(iArr2));
	    System.out.println("iArr3 Fibonacci: "+ isFibonacci(iArr3));
	    System.out.println("iArr4 Fibonacci: "+ isFibonacci(iArr4));
	}
	
	public static boolean isFibonacci(int[] iArr) {
		
		if (iArr.length==0)
			return false;
		
		if ((iArr.length==1)&&(iArr[0]==0))
			return true;

		if ((iArr.length==2)&&(iArr[0]==0)&&(iArr[1]==1))
			return true;
		
		for (int i=0; i<iArr.length-2; i++){
			if (!((iArr[i]+iArr[i+1])==iArr[i+2]))
					return false;
		}
		return true;
		
    }
}

/* Result
iArr1 Fibonacci: false
iArr2 Fibonacci: false
iArr3 Fibonacci: false
iArr4 Fibonacci: true
*/
